﻿#include "stdafx.h"

void SwapKey(std::wstring& key)
{
	const std::wstring changedKey = key;
	const unsigned int keyLen     = key.length();

	for (unsigned int i = 0; i < keyLen; ++i)
	{
		key[++i] ^= i;
	}
}

void CryptDecrypt(std::wstring& msg, std::wstring& key)
{
	const unsigned int msgLen = msg.length();
	const unsigned int keyLen = key.length();

	printf("Input string: %ls\n", msg.c_str());
	printf("StartLenght = %d\n", msg.length());

	SwapKey(key);

	for (unsigned int i = 0; i < msgLen; ++i)
	{
		for (unsigned int j = 0; j < keyLen; ++j)
		{
			msg[i] ^= key[j];
		}
	}

	printf("Output string: %ls\n", msg.c_str());
	printf("FinishLenght = %d\n", msg.length());
}

int _tmain(int argc, _TCHAR* argv[])
{
	if (argc == 3)
	{
		std::wstring msg = argv[1];
		std::wstring key = argv[2];

		CryptDecrypt(msg, key);
	}
	else
	{
		printf("Wrong parameters!\n");
	}

	_getch();
	return 0;
}